package models

import (
	"gorm.io/gorm"
	"time"
	"user-srv/basic/inits"
)

type UserPoints struct {
	Id          uint32         `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	UserId      uint32         `gorm:"column:user_id;type:int UNSIGNED;comment:用户ID;not null;" json:"user_id"`          // 用户ID
	TotalPoints uint32         `gorm:"column:total_points;type:int UNSIGNED;comment:总积分;not null;" json:"total_points"` // 总积分
	PointsDay   uint32         `gorm:"column:points_day;type:int UNSIGNED;comment:连续签到的天数;not null;" json:"points_day"` // 连续签到的天数
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP;" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime;default:NULL;" json:"deleted_at"`
}

func (u *UserPoints) TableName() string {
	return "user_points"
}

func (u *UserPoints) GetUserPointsById() error {
	return inits.DB.Where("user_id = ?", u.UserId).First(&u).Error
}
func (u *UserPoints) AddUserPoints() error {
	return inits.DB.Create(&u).Error
}
func (u *UserPoints) UpdateUserPoints() error {
	return inits.DB.Where("user_id = ?", u.UserId).Updates(&u).Error
}
